package xyz.yuzegod.megawalls.timer;

import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import xyz.yuzegod.megawalls.game.GamePlayer;
import xyz.yuzegod.megawalls.spectator.SpectatorTarget;

public class CompassTimer implements Runnable
{
    @Override
    public void run() {
        for (final GamePlayer online : GamePlayer.getOnlinePlayers()) {
            if (online.isSpectator()) {
                final SpectatorTarget target = online.getSpectatorTarget();
                target.sendTip();
                target.autoTp();
            }
            else {
                final Player player = online.getPlayer();
                final ItemStack itemStack = player.getItemInHand();
                if (itemStack == null || itemStack.getType() != Material.COMPASS) {
                    continue;
                }
                online.getPlayerCompass().sendClosestPlayer();
            }
        }
    }
}
